import { Component, OnInit, Output, EventEmitter } from '@angular/core';

import { HintsService } from '../../../../public/serve/hints/hints.service';
import { CudTableService } from 'app/public/serve/cud-table/cud-table.service';
import { Service } from '../../../../server/server';
import { appProductUrl } from '../../../product.url';
import { product } from '../../../product.data';


declare var $: any;

@Component({
	selector: 'app-product-indexing-task-complete',
	templateUrl: './product-indexing-task-complete.component.html'
})
export class ProductIndexingTaskCompleteComponent implements OnInit {

	one: any;
	id: any;
	@Output() completeEvent = new EventEmitter<void>();

	constructor(
        private server: Service,
		private request: CudTableService,
		private hintsService: HintsService
	) { }

	ngOnInit() {
	}

	setData(taskData) {
		this.id = taskData.taskId;
	}

	/**
	 * 结案(主任务)
	 */
	setCompleteStatus() {
		const params = {
			token: product.retrieval.token,
			id: this.id,
			completestatus: "1"
		}
		this.request.postRequest(this.server.baseUrl +appProductUrl.setTaskComplete, params).then(res => {
			if (res.result_code === '0000') {
				this.completeEvent.emit();
			}
			this.hintsService.messages(res.message, res.result_code);
			return;
		}).catch((err: any) => {
			this.hintsService.messages('error', 'error');
			return;
		});
	}
}
